home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_spinner_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  8KB  |  207 lines

  1. #include "ewl_test.h"
  2.  
  3. Ewl_Widget     *tmp_win;
  4.  
  5. static Ewl_Widget *spinner_button;
  6. static Ewl_Widget *spinner[4];
  7.  
  8. static void __spinner_window_configure(Ewl_Widget * w, void *ev_data,
  9.                      void *user_data);
  10.  
  11. static void
  12. __destroy_spinner_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  13.                     void *user_data __UNUSED__)
  14. {
  15.     ewl_widget_destroy(w);
  16.     ewl_callback_append(spinner_button, EWL_CALLBACK_CLICKED,
  17.                 __create_spinner_test_window, NULL);
  18.     ewl_widget_destroy(tmp_win);
  19. }
  20.  
  21. static void
  22. __spinner_value_changed(Ewl_Widget * w __UNUSED__, void *ev_data __UNUSED__,
  23.                     void *user_data __UNUSED__)
  24. {
  25.     int             xx, yy, ww, hh;
  26.  
  27.     xx = (int) (ewl_spinner_value_get(EWL_SPINNER(spinner[0])));
  28.     yy = (int) (ewl_spinner_value_get(EWL_SPINNER(spinner[1])));
  29.     ww = (int) (ewl_spinner_value_get(EWL_SPINNER(spinner[2])));
  30.     hh = (int) (ewl_spinner_value_get(EWL_SPINNER(spinner[3])));
  31.  
  32.     ewl_callback_del(tmp_win, EWL_CALLBACK_CONFIGURE,
  33.              __spinner_window_configure);
  34.  
  35.     ewl_window_move(EWL_WINDOW(tmp_win), xx, yy);
  36.     ewl_object_size_request(EWL_OBJECT(tmp_win), ww, hh);
  37.  
  38.     ewl_callback_append(tmp_win, EWL_CALLBACK_CONFIGURE,
  39.                 __spinner_window_configure, NULL);
  40. }
  41.  
  42. static void
  43. __spinner_window_configure(Ewl_Widget * w __UNUSED__, void *ev_data __UNUSED__,
  44.                         void *user_data __UNUSED__)
  45. {
  46.     int xx, yy, ww, hh;
  47.  
  48.     ewl_window_position_get(EWL_WINDOW(tmp_win), &xx, &yy);
  49.     ewl_object_current_size_get(EWL_OBJECT(tmp_win), &ww, &hh);
  50.  
  51.     ewl_spinner_value_set(EWL_SPINNER(spinner[0]), (double) (xx));
  52.     ewl_spinner_value_set(EWL_SPINNER(spinner[1]), (double) (yy));
  53.     ewl_spinner_value_set(EWL_SPINNER(spinner[2]), (double) (ww));
  54.     ewl_spinner_value_set(EWL_SPINNER(spinner[3]), (double) (hh));
  55. }
  56.  
  57. void
  58. __create_spinner_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  59.                     void *user_data __UNUSED__)
  60. {
  61.     Ewl_Widget     *spinner_win;
  62.     Ewl_Widget     *spinner_box;
  63.     Ewl_Widget     *spinner_row;
  64.     Ewl_Widget     *text[4];
  65.     Ewl_Widget     *separator[3];
  66.     int             xx, yy, ww, hh, mw, mh;
  67.  
  68.     spinner_button = w;
  69.  
  70.     spinner_win = ewl_window_new();
  71.     ewl_window_title_set(EWL_WINDOW(spinner_win), "STest");
  72.     ewl_window_name_set(EWL_WINDOW(spinner_win), "EWL Test Application");
  73.     ewl_window_class_set(EWL_WINDOW(spinner_win), "EFL Test Application");
  74.  
  75.     if (w) {
  76.         ewl_callback_del(w, EWL_CALLBACK_CLICKED, 
  77.                 __create_spinner_test_window);
  78.         ewl_callback_append(spinner_win, EWL_CALLBACK_DELETE_WINDOW,
  79.                     __destroy_spinner_test_window, NULL);
  80.     } else
  81.         ewl_callback_append(spinner_win, EWL_CALLBACK_DELETE_WINDOW,
  82.                     __close_main_window, NULL);
  83.     ewl_widget_show(spinner_win);
  84.  
  85.     /*
  86.      * Create the main box for holding the widgets
  87.      */
  88.     spinner_box = ewl_vbox_new();
  89.     ewl_container_child_append(EWL_CONTAINER(spinner_win), spinner_box);
  90.     ewl_box_spacing_set(EWL_BOX(spinner_box), 10);
  91.     ewl_widget_show(spinner_box);
  92.  
  93.     tmp_win = ewl_window_new();
  94.     ewl_callback_append(tmp_win, EWL_CALLBACK_CONFIGURE,
  95.                 __spinner_window_configure, NULL);
  96.     ewl_widget_show(tmp_win);
  97.     ewl_window_borderless_set(EWL_WINDOW(tmp_win));
  98.  
  99.     /*
  100.      * Grab the current coordinates of the window we will manipulate.
  101.      */
  102.     ewl_object_current_geometry_get(EWL_OBJECT(tmp_win), &xx, &yy, &ww,
  103.                     &hh);
  104.     ewl_object_minimum_size_get(EWL_OBJECT(tmp_win), &mw, &mh);
  105.  
  106.     spinner_row = ewl_hbox_new();
  107.     ewl_container_child_append(EWL_CONTAINER(spinner_box), spinner_row);
  108.     ewl_widget_show(spinner_row);
  109.  
  110.     text[0] = ewl_text_new();
  111.     ewl_text_text_set(EWL_TEXT(text[0]), "X");
  112.     ewl_object_fill_policy_set(EWL_OBJECT(text[0]), EWL_FLAG_FILL_NONE);
  113.     ewl_object_alignment_set(EWL_OBJECT(text[0]), EWL_FLAG_ALIGN_CENTER);
  114.     ewl_container_child_append(EWL_CONTAINER(spinner_row), text[0]);
  115.     ewl_widget_show(text[0]);
  116.  
  117.     spinner[0] = ewl_spinner_new();
  118.     ewl_spinner_digits_set(EWL_SPINNER(spinner[0]), 0);
  119.     ewl_spinner_min_val_set(EWL_SPINNER(spinner[0]), 0);
  120.     ewl_spinner_max_val_set(EWL_SPINNER(spinner[0]), 1280);
  121.     ewl_spinner_value_set(EWL_SPINNER(spinner[0]), (double) (xx));
  122.     ewl_spinner_step_set(EWL_SPINNER(spinner[0]), 1.0);
  123.     ewl_container_child_append(EWL_CONTAINER(spinner_row), spinner[0]);
  124.     ewl_callback_append(spinner[0], EWL_CALLBACK_VALUE_CHANGED,
  125.                 __spinner_value_changed, NULL);
  126.     ewl_widget_show(spinner[0]);
  127.  
  128.     separator[0] = ewl_hseparator_new();
  129.     ewl_container_child_append(EWL_CONTAINER(spinner_box), separator[0]);
  130.     ewl_widget_show(separator[0]);
  131.  
  132.     spinner_row = ewl_hbox_new();
  133.     ewl_container_child_append(EWL_CONTAINER(spinner_box), spinner_row);
  134.     ewl_widget_show(spinner_row);
  135.  
  136.     text[1] = ewl_text_new();
  137.     ewl_text_text_set(EWL_TEXT(text[1]), "Y");
  138.     ewl_object_fill_policy_set(EWL_OBJECT(text[1]), EWL_FLAG_FILL_NONE);
  139.     ewl_object_alignment_set(EWL_OBJECT(text[1]), EWL_FLAG_ALIGN_CENTER);
  140.     ewl_container_child_append(EWL_CONTAINER(spinner_row), text[1]);
  141.     ewl_widget_show(text[1]);
  142.  
  143.     spinner[1] = ewl_spinner_new();
  144.     ewl_spinner_digits_set(EWL_SPINNER(spinner[1]), 0);
  145.     ewl_spinner_min_val_set(EWL_SPINNER(spinner[1]), 0);
  146.     ewl_spinner_max_val_set(EWL_SPINNER(spinner[1]), 1024);
  147.     ewl_spinner_value_set(EWL_SPINNER(spinner[1]), (double) (yy));
  148.     ewl_spinner_step_set(EWL_SPINNER(spinner[1]), 1.0);
  149.     ewl_container_child_append(EWL_CONTAINER(spinner_row), spinner[1]);
  150.     ewl_callback_append(spinner[1], EWL_CALLBACK_VALUE_CHANGED,
  151.                 __spinner_value_changed, NULL);
  152.     ewl_widget_show(spinner[1]);
  153.  
  154.     separator[1] = ewl_hseparator_new();
  155.     ewl_container_child_append(EWL_CONTAINER(spinner_box), separator[1]);
  156.     ewl_widget_show(separator[1]);
  157.  
  158.     spinner_row = ewl_hbox_new();
  159.     ewl_container_child_append(EWL_CONTAINER(spinner_box), spinner_row);
  160.     ewl_widget_show(spinner_row);
  161.  
  162.     text[2] = ewl_text_new();
  163.     ewl_text_text_set(EWL_TEXT(text[2]), "W");
  164.     ewl_object_fill_policy_set(EWL_OBJECT(text[2]), EWL_FLAG_FILL_NONE);
  165.     ewl_object_alignment_set(EWL_OBJECT(text[2]), EWL_FLAG_ALIGN_CENTER);
  166.     ewl_container_child_append(EWL_CONTAINER(spinner_row), text[2]);
  167.     ewl_widget_show(text[2]);
  168.  
  169.     spinner[2] = ewl_spinner_new();
  170.     ewl_spinner_digits_set(EWL_SPINNER(spinner[2]), 0);
  171.     ewl_spinner_min_val_set(EWL_SPINNER(spinner[2]), (double) (mw));
  172.     ewl_spinner_max_val_set(EWL_SPINNER(spinner[2]), 1280);
  173.     ewl_spinner_value_set(EWL_SPINNER(spinner[2]), (double) (ww));
  174.     ewl_spinner_step_set(EWL_SPINNER(spinner[2]), 1.0);
  175.     ewl_container_child_append(EWL_CONTAINER(spinner_row), spinner[2]);
  176.     ewl_callback_append(spinner[2], EWL_CALLBACK_VALUE_CHANGED,
  177.                 __spinner_value_changed, NULL);
  178.     ewl_widget_show(spinner[2]);
  179.  
  180.     separator[2] = ewl_hseparator_new();
  181.     ewl_container_child_append(EWL_CONTAINER(spinner_box), separator[2]);
  182.     ewl_widget_show(separator[2]);
  183.  
  184.     spinner_row = ewl_hbox_new();
  185.     ewl_container_child_append(EWL_CONTAINER(spinner_box), spinner_row);
  186.     ewl_widget_show(spinner_row);
  187.  
  188.     text[3] = ewl_text_new();
  189.     ewl_text_text_set(EWL_TEXT(text[3]), "H");
  190.     ewl_object_fill_policy_set(EWL_OBJECT(text[3]), EWL_FLAG_FILL_NONE);
  191.     ewl_object_alignment_set(EWL_OBJECT(text[3]), EWL_FLAG_ALIGN_CENTER);
  192.     ewl_container_child_append(EWL_CONTAINER(spinner_row), text[3]);
  193.     ewl_widget_show(text[3]);
  194.  
  195.     spinner[3] = ewl_spinner_new();
  196.     ewl_spinner_digits_set(EWL_SPINNER(spinner[3]), 0);
  197.     ewl_spinner_min_val_set(EWL_SPINNER(spinner[3]), (double) (mh));
  198.     ewl_spinner_max_val_set(EWL_SPINNER(spinner[3]), 1024);
  199.     ewl_spinner_value_set(EWL_SPINNER(spinner[3]), (double) (hh));
  200.     ewl_spinner_step_set(EWL_SPINNER(spinner[3]), 1.0);
  201.     ewl_container_child_append(EWL_CONTAINER(spinner_row), spinner[3]);
  202.     ewl_callback_append(spinner[3], EWL_CALLBACK_VALUE_CHANGED,
  203.                 __spinner_value_changed, NULL);
  204.     ewl_widget_show(spinner[3]);
  205. }
  206.  
  207.